import AutoLoad from "./AutoLoad"

const { ccclass, property, disallowMultiple, executionOrder, requireComponent, menu } = cc._decorator

/**
 * 判断加载组件
 */
@ccclass
@disallowMultiple
@executionOrder(-1)
@menu("component/JudgeLoad")
@requireComponent(AutoLoad)
export default class JudgeLoad extends cc.Component {

    @property()
    editor = true

    @property()
    preview = true

    @property()
    browser = true

    onLoad() {
        this.getComponent(AutoLoad).enabled = this.checkEnable()
    }

    checkEnable() {
        if (CC_EDITOR) {
            if (!this.editor) {
                return false
            }
        }

        if (CC_PREVIEW) {
            if (!this.preview) {
                return false
            }
        }

        if (cc.sys.isBrowser) {
            if (!this.browser) {
                return false
            }
        }

        return true
    }
}
